package Person;

import java.util.HashSet;
import java.util.Set;

public class Person {
    private String name;
    private int age;

    public Person(String name,int age)
    {
        this.name = name;
        this.age = age;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getAge()
    {
        return age;
    }

    public void setAge(int age)
    {
        this.age = age;
    }

    @Override
    public boolean equals(Object obj)
    {
        if(this == obj)
        {
            return true;
        }
        if(obj == null||getClass()!=obj.getClass())
        {
            return false;
        }
        Person person = (Person)obj;
        return name.equals(person.name);
    }

    @Override
    public int hashCode()
    {
        return name.hashCode();
    }

    @Override
    public String toString()
    {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args)
    {
        Set<Person> set = new HashSet<>();
        set.add(new Person("Tom",18));
        set.add(new Person("Bob",19));
        set.add(new Person("Tom",20));

        for(Person person : set)
        {
            System.out.println(person);
        }
    }
}
